package com.tbit.uqbike.service.business.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tbit.uqbike.constant.enums.AccountSumStatEnum;
import com.tbit.uqbike.object.pojo.AccountSumStat;
import com.tbit.uqbike.object.view.NameObject;
import com.tbit.uqbike.service.business.AccountSumStatService;
import com.tbit.uqbike.webmanager.dao.stat.AccountSumStatDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @Author:BUGTian
 * @DATE: 2022/11/7
 */
@Service
public class AccountSumStatServiceImpl extends ServiceImpl<AccountSumStatDao, AccountSumStat> implements AccountSumStatService {

    @Autowired
    private AccountSumStatDao accountSumStatDao;

    @Override
    public List<NameObject> statUserData(List<Integer> idList, Integer branchId) {
        Map<Integer, Map<String, Object>> dataMap = accountSumStatDao.statAccountSumData(idList, branchId);
        List<NameObject> resultList = new LinkedList<>();
        for (AccountSumStatEnum accountSumStatEnum : AccountSumStatEnum.getUserDataEnum()) {
            Map<String, Object> typeMap = dataMap.get(accountSumStatEnum.getDataType());
            resultList.add(new NameObject(accountSumStatEnum.getFieldName(), typeMap == null ? 0 : typeMap.get("cntTotal")));
        }
        return resultList;
    }


}
